package net.seehope.foodie.code;

import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.time.LocalDateTime;

//验证码的父类
public class ValidateCode implements Serializable{
	/**
	 * 不管是什么验证码，都是具有三个基本逻辑的
	 * 
	 * 1.生成
	 * 2.存储
	 * 3.发送
	 * 4.验证
	 * 
	 * 该类有封装有三个字段，验证码，验证码图片，以及验证码过期时间。过期时间分为过期时间点和多少秒后过期
	 */
	private static final long serialVersionUID = 1L;
	/*
	 * 验证码的内容
	 */
	private String code;
	/*
	 * 有效期，在这个时间节点之前是有效的
	 */
	private LocalDateTime expireTime;
	
	
	private BufferedImage image;
	
	//判断当前验证码是否过期
	public Boolean isExpried() {
		return LocalDateTime.now().isAfter(this.expireTime);
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public LocalDateTime getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(LocalDateTime expireTime) {
		this.expireTime = expireTime;
	}

	public ValidateCode() {}
	
	
	/**
	 * 
	 * @param code
	 * @param expireTime 过期的时间点
	 * @param image
	 */
	public ValidateCode(String code, LocalDateTime expireTime,BufferedImage image) {
		this.image = image;
		this.code = code;
		this.expireTime = expireTime;
	}
	
	/**
	 * 
	 * @param code
	 * @param expireln 多少秒之后过期 单位是秒
	 * @param image
	 */
	public ValidateCode(String code, int expireln,BufferedImage image) {
		this.code = code;
		this.expireTime = LocalDateTime.now().plusSeconds(expireln);
		this.image = image;
	}
	
	public void setExpireTime(int expireln) {
		this.expireTime = LocalDateTime.now().plusSeconds(expireln);
	}

	public BufferedImage getImage() {
		return image;
	}

	public void setImage(BufferedImage image) {
		this.image = image;
	}
	
	
	
	
}
